home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_03
/
cindric
/
inssort.c
< prev
Wrap
Text File
|
1994-12-29
|
1KB
|
46 lines
/*----------------------------*
* Special Insertion Sort *
* (c) 1994, Blase B. Cindric *
* All rights reserved, and *
* jealously guarded *
*----------------------------*/
void special_insertion_sort(
unsigned *list, /* array to be sorted */
int n, /* no. of elements in array */
int num_sorted) /* no. of elements already in order */
{
int j, k;
unsigned item_to_place;
/*-------------------------------------------*
* subscripts for sorted portion of array: *
* 0 to (num_sorted - 1) *
* subscripts for unsorted portion: *
* num_sorted to n *
*-------------------------------------------*/
for (k = num_sorted; k < n; k++) {
/* move new item out of array */
item_to_place = list[k];
/* copy all values larger than new item down one
place in the array */
for (j = k - 1; list[j] > item_to_place && j >= 0; j--)
list[j+1] = list[j];
/* place new item in its proper array position */
list[j+1] = item_to_place;
} /* end of outer for loop */
} /* end of special insertion sort */